﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace TinyERP.Framework.Controls
{
    public class DialogHelper 
    {
        private Form form;
        private DialogHelper()
        {
            
        }
        public DialogHelper(IDialog dialogForm)
        {
            form = (Form)dialogForm;
            form.Text = dialogForm.GetHeaderText();

            form.AutoSize = true;
            form.AcceptButton = dialogForm.GetAcceptButton();
            form.CancelButton = dialogForm.GetCancelButton();
            form.ShowInTaskbar = false;
            form.MaximizeBox = false;
            form.MinimizeBox = false;
            form.Text = dialogForm.GetHeaderText();
            form.StartPosition = FormStartPosition.CenterParent;
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.ClientSize = ((Form)dialogForm).Size;
            form.KeyPreview = true;
            dialogForm.RegisterShortcuts();
            dialogForm.CloseDialog += new CloseDialogHandler(OnCloseDialog);
            form.KeyDown += new KeyEventHandler(OnKeyDown);
        }
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                ((Form)sender).Close();
            }
            ShortcutHandler.GetInstance().HandleEvent(e);
        }
        private void OnCloseDialog(Form screen)
        {
            screen.Close();
        }
        public void ShowDialog()
        {
            form.ShowDialog();
        }
        public void ShowDialog(Form parentForm)
        {
            form.ShowDialog(parentForm);
        }

       



        
    }
}
